<meta charset="UTF-8">
<div class="easyui-panel" title="查询" data-options="fit:true"
	style="display: flex; flex-direction: column;">
	<p style="flex-flow: 0;">
		<label>选择班级：</label> <input id="aclass" class="easyui-combobox"
			data-options="
			url:'banji/list',
						valueField:'id',
						textField:'name',
						panelHeight:'auto',
						editable:false,
						icons:[{
					        iconCls:'icon-clear',
					        handler: function(e){
					       	 $(e.data.target).textbox('clear');
					        	$('#div3').hide();
					        }
					  		  }],
		" />
		<label>选择学生：</label> <input id="stu" class="easyui-combobox"
			data-options="
						
						url:'grade/getStu?bjId=',
						valueField:'id',
						textField:'name',
						panelHeight:'auto',
						editable:false,
						icons:[{
								        iconCls:'icon-clear',
								        handler: function(e){
								       	 	$(e.data.target).textbox('clear');
								        	$('#div3').hide();
								        }
								  	}],
		" />
		<button class="easyui-linkbutton" data-options="iconCls:'icon-search'"
			id="cx">查询</button>
	</p>
	<div id="div3" style="flex-grow: 1; display: none;">
		<table id="bjcj">
			<thead>
				<tr>
					<th data-options="field:'id',hidden:true">ID</th>
					<th width="200"
						data-options="field:'student',sortable: true,formatter:function(val,row,index){
							return row.student.stuNo;
								}">学号</th>
					<th width="300"
						data-options="field:'name',formatter:function(val,row,index){
								return row.student.name;
								}">姓名</th>
					<th width="300"
						data-options="field:'course',formatter:function(val,row,index){
								return row.course.name;
								}">课程名称</th>
					<th width="200" data-options="field:'grade'">成绩</th>
				</tr>

			</thead>

		</table>
	</div>
</div>
<script type="text/javascript">
$(function(){
	$('#aclass').combobox({
		onSelect:function(e){
			var bjId=e.id;
			$('#stu').combobox({
				url:'grade/getStu?bjId='+bjId,
			})
			$('#stu').combobox('enable');
		}
	})
	var grid = $('#bjcj');
	$('#cx').bind('click',function(){
		var stuId=$('#stu').combobox('getValue');
		var bjId=$('#aclass').combobox('getValue');
		if(bjId==0||stuId==0){
				$('#div3').hide();
				return;
			}else{
				$('#div3').show();
				cjChange1(bjId,stuId);
		}
	
		grid.datagrid({
			fit: true,
			url: 'grade/getPersonGrade?stuId='+stuId,
			singleSelect: true,
			fitColumns: true,
			autoRowHeight: true,
			striped: true,
			idField: 'id',
			sortName: 'id',
			sortOrder: 'asc',
			pageList: [5, 10, 20, 30],
			pagination: true,
		});

	});
	
})
 function formatOper(val, row, index) {   
 	if(row.grade==null){

       row.grade=0;
	 	}
	 		 return '<input id="input" value="'+row.grade+'"/>';
    }

$("input[id='input']").numberbox({
    min:0,
    precision:0
});
function cjChange1(bjId,stuId){
	$('#bjcj').datagrid($.extend({},$.crudgrid.defaults,{
		url:'grade/getPersonGrade?stuId='+stuId,
		onLoadSuccess:function(data){
	            $("input[id='input']").numberbox({
	            	onChange:function(grade,oldgrade){
		            	var grid=$('#bjcj').datagrid('getSelected');
						xg(grid.id,grade);
		            }
		        });  
	   	}
	}))
};
function xg(id,grade){
	if(!(/^[0-9]\d*$/.test(grade))){
		$.messager.alert('提示','请输入正整数','info');
		return;
	};
$.post('grade/cjChange1',{id:id,grade:grade},function(data){});
}
</script>

